# -*- coding:utf-8 -*-

'''
1对字符串中的每个字符进行判断分析
2e（E）后面只能接数字，并且不能出现2次
3对于+、-号，只能出现在第一个字符或者是e的后一位
4对于小数点，不能出现2次，e后面不能出现小数点
'''
class Solution:
    # s字符串
    def isNumeric(self, s):
        # write code here
        if len(s) == 0:
            return False
        s = [w.lower() for w in s]
        # 2
        if 'e' in s :
            indexE = s.index('e')
            first = s[:indexE]
            last = s[indexE+1:]
            # 4
            if '.' in last or len(last)==0:
                return False
            isFront = self.scanDigit(first)
            isBehind = self.scanDigit(last)
            return isFront and isBehind
        else:
            return self.scanDigit(s)

    def scanDigit(self,s):
        dotNum = 0
        allowVal = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '.', 'e']
        # 1
        for i in range(len(s)):
            if s[i] not in allowVal:
                return False
            if s[i]=='.':
                dotNum+=1
            #     3
            if s[i] in '+-' and i!=0:
                return False
        #     4
        if dotNum>1:
            return False
        return True